home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / hypercrd / hc1_2_x / inptmthd.sit / Input Methods / card_6294.txt < prev    next >
Text File  |  1989-11-24  |  5KB  |  233 lines

  1. -- card: 6294 from stack: in
  2. -- bmap block id: 6531
  3. -- flags: 0000
  4. -- background id: 2696
  5. -- name: Expressions
  6. ----- HyperTalk script -----
  7. on openCard
  8.   -- put insertion point at beginning of field
  9.   unlock screen
  10.   select before char 1 of card field "Input"
  11.   pass openCard
  12. end openCard
  13.  
  14. on closeCard
  15.   lock screen
  16.   put empty into card field "Input"
  17.   put empty into card field "Input2"
  18.   pass closeCard
  19. end closeCard
  20.  
  21.  
  22. -- "Cleans up" a mathematical expression
  23. -- Remove illegal characters from expression
  24. -- Skips any characters specified as "allowable"
  25. -- Replace x and ├╖ with what HyperCard wants
  26. function cleanExpr expr, allowable
  27. put "0123456789" into numeric
  28. put 1 into c
  29. repeat until c > the number of chars in expr
  30.   put char c of expr into ch
  31.   if ch is in allowable then
  32.     add 1 to c
  33.   else
  34.     if ch is in " 0123456789.+-*x/├╖^()" then
  35.       if ch = "x" then
  36.         put "*" into char c of expr
  37.       else if ch = "├╖" then
  38.         put "/" into char c of expr
  39.       end if
  40.       add 1 to c
  41.     else  -- invalid character: delete it
  42.       delete char c of expr
  43.     end if
  44.   end if
  45. end repeat
  46. if expr is empty then return 0
  47. else return expr
  48. end cleanExpr
  49.  
  50.  
  51. -- Compare two expressions of one variable (x)
  52. -- Returns true if they are equivalent
  53. function equivalent expr1, expr2
  54. put cleanExpr(expr1,"x") into expr1
  55. put cleanExpr(expr2,"x") into expr2
  56. put true into match
  57. -- check twice to make sure we don't get a fluke match
  58. repeat 2 times
  59.   put random(999) into x
  60.   if the value of expr1 Γëá the value of expr2
  61.   then put false into match
  62. end repeat
  63. return match
  64. end equivalent
  65.  
  66.  
  67.  
  68.  
  69.  
  70. -- part 1 (field)
  71. -- low flags: 01
  72. -- high flags: 0000
  73. -- rect: left=23 top=65 right=106 bottom=245
  74. -- title width / last selected line: 0
  75. -- icon id / first selected line: 0 / 0
  76. -- text alignment: 0
  77. -- font id: 3
  78. -- text size: 14
  79. -- style flags: 0
  80. -- line height: 18
  81. -- part name: 
  82.  
  83.  
  84. -- part 3 (field)
  85. -- low flags: 02
  86. -- high flags: 0002
  87. -- rect: left=66 top=116 right=134 bottom=196
  88. -- title width / last selected line: 0
  89. -- icon id / first selected line: 0 / 0
  90. -- text alignment: 0
  91. -- font id: 0
  92. -- text size: 12
  93. -- style flags: 0
  94. -- line height: 16
  95. -- part name: Input
  96. ----- HyperTalk script -----
  97. on returnInField
  98.   if the value of cleanExpr(me,"") is 35.70 then rightSound
  99.   else
  100.     wrongSound
  101.     select line 1 of me
  102.   end if
  103. end returnInField
  104.  
  105.  
  106.  
  107. -- part 4 (field)
  108. -- low flags: 00
  109. -- high flags: 0000
  110. -- rect: left=26 top=165 right=206 bottom=248
  111. -- title width / last selected line: 0
  112. -- icon id / first selected line: 0 / 0
  113. -- text alignment: 0
  114. -- font id: 3
  115. -- text size: 14
  116. -- style flags: 0
  117. -- line height: 18
  118. -- part name: 
  119.  
  120.  
  121. -- part 5 (field)
  122. -- low flags: 00
  123. -- high flags: 0000
  124. -- rect: left=43 top=227 right=245 bottom=216
  125. -- title width / last selected line: 0
  126. -- icon id / first selected line: 0 / 0
  127. -- text alignment: 0
  128. -- font id: 0
  129. -- text size: 12
  130. -- style flags: 0
  131. -- line height: 16
  132. -- part name: 
  133.  
  134.  
  135. -- part 7 (field)
  136. -- low flags: 02
  137. -- high flags: 0000
  138. -- rect: left=69 top=251 right=269 bottom=244
  139. -- title width / last selected line: 0
  140. -- icon id / first selected line: 0 / 0
  141. -- text alignment: 0
  142. -- font id: 0
  143. -- text size: 12
  144. -- style flags: 0
  145. -- line height: 16
  146. -- part name: Input2
  147. ----- HyperTalk script -----
  148. on returnInField
  149.   if equivalent(me, "3*x + 2*(12*x + 4)") then rightSound
  150.   else
  151.     wrongSound
  152.     select line 1 of me
  153.   end if
  154. end returnInField
  155.  
  156.  
  157.  
  158. -- part 8 (field)
  159. -- low flags: 00
  160. -- high flags: 0000
  161. -- rect: left=43 top=251 right=269 bottom=70
  162. -- title width / last selected line: 0
  163. -- icon id / first selected line: 0 / 0
  164. -- text alignment: 0
  165. -- font id: 0
  166. -- text size: 12
  167. -- style flags: 0
  168. -- line height: 16
  169. -- part name: 
  170.  
  171.  
  172. -- part 9 (button)
  173. -- low flags: 00
  174. -- high flags: 2001
  175. -- rect: left=490 top=320 right=342 bottom=512
  176. -- title width / last selected line: 0
  177. -- icon id / first selected line: 26635 / 26635
  178. -- text alignment: 1
  179. -- font id: 0
  180. -- text size: 12
  181. -- style flags: 0
  182. -- line height: 16
  183. -- part name: 
  184. ----- HyperTalk script -----
  185. on mouseUp
  186.   info
  187. end mouseUp
  188.  
  189.  
  190.  
  191. -- part 10 (field)
  192. -- low flags: 81
  193. -- high flags: 2004
  194. -- rect: left=267 top=83 right=287 bottom=504
  195. -- title width / last selected line: 0
  196. -- icon id / first selected line: 0 / 0
  197. -- text alignment: 0
  198. -- font id: 3
  199. -- text size: 12
  200. -- style flags: 0
  201. -- line height: 16
  202. -- part name: Info
  203. ----- HyperTalk script -----
  204. on mouseUp
  205.   info
  206. end mouseUp
  207.  
  208.  
  209. -- part contents for card part 1
  210. ----- text -----
  211. A $42 shirt is on sale for 15% off.  What is the new price?
  212.  
  213. -- part contents for card part 4
  214. ----- text -----
  215. Enter another form of the following equation.
  216.  
  217. -- part contents for card part 5
  218. ----- text -----
  219. y = 3*x + 2*(12x + 4)
  220.  
  221. -- part contents for card part 8
  222. ----- text -----
  223. y =
  224.  
  225. -- part contents for card part 10
  226. ----- text -----
  227. Note that you can type ANY expression for the shirt price:
  228.   35.7
  229.   42 - .15 * 42
  230.   35 + .7
  231. And you can type ANY equivalent equation.
  232.  
  233. This is because the answers are evaluated numerically before any matching is done.  (See the scripts for details.)